package flatlandRPG;

import org.lwjgl.opengl.GL11;

// -------------------------------------------------------------------------
/**
 * A regular polygon. Drawn as lines.
 *
 * @author Evan Tatarka (evant)
 * @version Apr 4, 2011
 */
public class GLRegularPolygon
    extends GLObject
{
    private float radius;
    private int   sides;


    /**
     * Constructs a regular polygon with the given radius and number of sides.
     *
     * @param radius
     *            the radius of the polygon
     * @param sides
     *            the number of sides of the polygon
     */
    public GLRegularPolygon(float radius, int sides)
    {
        this.radius = radius;
        this.sides = sides;
    }


    @Override
    protected void drawObject()
    {
        GL11.glBegin(GL11.GL_LINE_LOOP);
        double angle = 360.0 / sides;
        for (double i = 0; i < 360; i += angle)
        {
            double degInRad = i * Math.PI / 180.0;
            GL11.glVertex2f(
                (float)Math.cos(degInRad) * radius,
                (float)Math.sin(degInRad) * radius);
        }
        GL11.glEnd();
    }


    // ----------------------------------------------------------
    /**
     * Returns the radius of the polygon.
     *
     * @return the radius.
     */
    public float getRadius()
    {
        return radius;
    }


    // ----------------------------------------------------------
    /**
     * Returns the number of sides of the polygon.
     *
     * @return the number of sides
     */
    public int getSides()
    {
        return sides;
    }
}
